//
//  LBMarginTextView.m
//  app
//
//  Created by 杨庆人 on 17/9/5.
//  Copyright © 2017年 广东联结电子商务有限公司. All rights reserved.
//

#import "LBMarginTextField.h"
#import <LBCategory/LBCategory.h>
#import <Masonry/Masonry.h>

@interface LBMarginTextField()
//下划线的左边距
@property(nonatomic , assign)CGFloat leftMargin;
//下划线的右边距
@property(nonatomic , assign)CGFloat rightMargin;
//下划线的高度
@property(nonatomic , assign)CGFloat height;
//下划线
@property(nonatomic , strong)UIImageView * imageView;
@end
@implementation LBMarginTextField
- (CGFloat)leftMargin{
    if (!_leftMargin) {
        _leftMargin = 0;
    }
    return _leftMargin;
}
- (CGFloat)rightMargin{
    if (!_rightMargin) {
        _rightMargin = 0;
    }
    return _rightMargin;
}
- (CGFloat)height{
    if (!_height) {
        _height = 1;
    }
    return _height;
}
- (instancetype)initWithCoder:(NSCoder *)coder
{
    self = [super initWithCoder:coder];
    if (self) {
        self.imageView.backgroundColor = [UIColor colorWithR:218 G:218 B:218 A:1];
        [self addSubview:self.imageView];
    }
    return self;
}
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.imageView.backgroundColor = [UIColor colorWithR:218 G:218 B:218 A:1];
        [self addSubview:self.imageView];
    }
    return self;
}
- (instancetype)init{
    self = [super init];
    if (self) {
        self.imageView.backgroundColor = [UIColor colorWithR:218 G:218 B:218 A:1];
        [self addSubview:self.imageView];
    }
    return self;
}
- (void)setLeftMargin:(CGFloat)leftMargin
          rightMargin:(CGFloat)rightMargin
               height:(CGFloat)height{
    self.leftMargin = leftMargin;
    self.rightMargin = rightMargin;
    self.height = height;
}
- (void)setLeftMargin:(CGFloat)leftMargin
          rightMargin:(CGFloat)rightMargin{
    self.leftMargin = leftMargin;
    self.rightMargin = rightMargin;
}
- (UIImageView *)imageView{
    if (!_imageView) {
        _imageView = [UIImageView new];
    }
    return _imageView;
}
- (void)awakeFromNib {
    [super awakeFromNib];
}

+ (Class)layerClass {
    
    return [CAShapeLayer class];
}
- (void)layoutSubviews {
    
    [super layoutSubviews];

    [_imageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(self.height);
        make.left.equalTo(self).mas_offset(self.leftMargin);
        make.right.equalTo(self).mas_offset(-self.rightMargin);
        make.bottom.equalTo(self).mas_offset(-self.height);
        
    }];
}


@end
